package experiments.mwe;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import org.apache.commons.io.IOUtils;

import wrappers.jwme.JWMEWrapper;
import wrappers.stanford.StanfordNLP;
import edu.mit.jmwe.data.IMWE;
import edu.mit.jmwe.data.IToken;
import edu.stanford.nlp.util.CoreMap;

public class MWE {

	private static String UNTAGGED_FILE = "C:\\temp\\raw\\a.txt";

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		try {
			JWMEWrapper jwme = JWMEWrapper.getInstance();
			// LinkedHashMap<String,String> sentence = new
			// LinkedHashMap<String,String>();
			// sentence.put("She", "DT");
			// sentence.put(" looked ", "VBD");
			// sentence.put("up", "RP");
			// sentence.put("the", "DT");
			// sentence.put(" world ", "NN");
			// sentence.put(" record ", "NN");
			// sentence.put(".", ".");
			//
			System.out.println("Loading stanford NLP");
			StanfordNLP stanfordNLP = StanfordNLP.getInstance();
			List<String> lines = (List<String>) IOUtils.readLines(new FileInputStream(UNTAGGED_FILE));
			System.out.println(lines.size() + " lines in " + UNTAGGED_FILE);

			List<LinkedHashMap<String, String>> sentences = new ArrayList<LinkedHashMap<String, String>>();
			System.out.println("Tagging sentences");

			for (String s : lines) {
				List<CoreMap> annotatedSentences = stanfordNLP.annotate(s);
				for (CoreMap sentence : annotatedSentences) {
					LinkedHashMap<String, String> annotatedSentence = stanfordNLP.extractAnnotationFromLabeledSentence("tokenization", sentence);
					sentences.add(annotatedSentence);
				}
			}
			System.out.println("Extracting MWES");

			for (LinkedHashMap<String, String> sentence : sentences) {
				List<IMWE<IToken>> mwes = jwme.simpleDetect(sentence);
				JWMEWrapper.prettyPrint(mwes);
			}

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	// public static List<LinkedHashMap<String,String>> tagFile(String
	// inputFile){
	// List<LinkedHashMap<String,String>> sentence = new
	// ArrayList<LinkedHashMap<String,String>>
	//
	// return
	//
	// }

}
